<?php
/**
 * 用户服务
 */

namespace polymerize\user\service;

use app\common\InstanceTrait;
use polymerize\auth\module\login\WechatAppGetPhone;
use polymerize\user\module\user\BindMobile;
use polymerize\user\module\user\CancelUser;
use polymerize\user\module\user\ChangeInfo;
use polymerize\user\module\user\ChangePassword;
use polymerize\user\module\user\ForgetPassword;
use polymerize\user\module\user\GetUserInfo;
use polymerize\user\module\user\OutLogin;
use polymerize\user\module\user\RelieveMobile;

class UserService
{
    use InstanceTrait;

    /**
     * 微信小程序获取手机号
     *
     * @param string $code
     * @param int    $uid
     * @return array
     */
    public function wechatAppGetPhone(string $code, int $uid): array
    {
        return WechatAppGetPhone::getInstance()->wechatAppGetPhone($code, $uid);
    }

    /**
     * 用户信息
     *
     * @param int $uid
     * @return array
     */
    public function getUserInfo(int $uid): array
    {
        return GetUserInfo::getInstance()->getUserInfo($uid);
    }

    /**
     * 退出登录
     *
     * @param int    $uid
     * @param string $token
     * @return bool
     */
    public function outLogin(int $uid, string $token): bool
    {
        return OutLogin::getInstance()->outLogin($uid, $token);
    }

    /**
     * 删除注销用户
     *
     * @param int    $uid
     * @param string $sessionId
     * @return bool
     */
    public function cancelUser(int $uid, string $sessionId): bool
    {
        return CancelUser::getInstance()->cancelUser($uid, $sessionId);
    }

    /**
     * 修改用户信息
     *
     * @param int    $uid
     * @param string $type
     * @param string $avatar
     * @param string $nickname
     * @param int    $sex
     * @param string $birthday
     * @return bool
     */
    public function changeInfo(int $uid, string $type, string $avatar, string $nickname, int $sex, string $birthday): bool
    {
        return ChangeInfo::getInstance()->changeInfo($uid, $type, $avatar, $nickname, $sex, $birthday);
    }

    /**
     * 手机验证码修改密码[发送短信验证]
     *
     * @param int    $uid
     * @param string $mobile
     * @param int    $smsCode
     * @param string $password
     * @return array
     */
    public function changePassword(int $uid, string $mobile, int $smsCode, string $password): array
    {
        return ChangePassword::getInstance()->changePassword($uid, $mobile, $smsCode, $password);
    }

    /**
     * 绑定手机号
     *
     * @param int    $uid
     * @param string $mobile
     * @param int    $smsCode
     * @param string $token
     * @return array
     */
    public function bindMobile(int $uid, string $mobile, int $smsCode, string $token): array
    {
        return BindMobile::getInstance()->bindMobile($uid, $mobile, $smsCode, $token);
    }

    /**
     * 解除手机号
     *
     * @param int    $uid
     * @param string $mobile
     * @param int    $smsCode
     * @return array
     */
    public function relieveMobile(int $uid, string $mobile, int $smsCode): array
    {
        return RelieveMobile::getInstance()->relieveMobile($uid, $mobile, $smsCode);
    }

    /**
     * 手机验证码忘记密码修改密码[发送短信验证]
     *
     * @param int    $mobile
     * @param int    $smsCode
     * @param string $password
     * @return array
     */
    public function forgetPassword(int $mobile, int $smsCode, string $password): array
    {
        return ForgetPassword::getInstance()->forgetPassword($mobile, $smsCode, $password);
    }
}